using huqiang.Core.HGUI;
using System;
using UnityEngine;
using huqiang.UIComposite;
using huqiang.UIEvent;
using huqiang;
using huqiang.Data;
using huqiang.UIModel;
using System.Collections.Generic;

public class PopMenuPage:UIPage
{
    //反射UI界面上的物体
    class View
    {
        public UserEvent Back;
        public PopMenu popMenu;
    }
    View view;
    List<string> A, B;
    public override void Initial(UIElement parent, object dat = null)
    {
        base.Initial(parent, dat);
        view = LoadUI<View>("baseUI", "PopMenuPage");//"baseUI"创建的bytes文件名,"page"为创建的页面名
        InitialEvent();
    }
    void InitialEvent()
    {
        view.popMenu.Enity.activeSelf = false;
        view.Back.Click = (o, e) => {
            view.popMenu.Clear();
            if (e.IsLeftButtonUp)
            {
                ShowLeftMenu();
            }
            else
            {
                ShowRightMenu();
            }
            view.popMenu.SetPosition(e.CanvasPos);
            view.popMenu.Enity.activeSelf = true;
        };
        view.popMenu.ItemClick = (o) => { 
            Debug.Log("Click:"+ o.Context.Content);
            view.popMenu.Enity.activeSelf = false;
        };
    }
    void ShowLeftMenu()
    {
        var context = view.popMenu.Root;
        context.Clear();
        CreateMenu(new string[]{ "1","2","3","4","5"},context);
        CreateMenu(new string[] { "21", "22", "23", "24", "25" }, context.GetChild(1));
        var c4= context.GetChild(3);
        CreateMenu(new string[] { "41", "42", "43", "44", "45" }, c4);
        var c45 = c4.GetChild(4);
        CreateMenu(new string[] { "451", "452", "453", "454", "455" }, c45);
        view.popMenu.Refresh();
    }
    void ShowRightMenu()
    {
        var context = view.popMenu.Root;
        context.Clear();
        CreateMenu(new string[] { "3", "4", "5", "6", "7", "8", "9", "10" }, context);
        CreateMenu(new string[] { "21", "22", "23", "24", "25" }, context.GetChild(1));
        var c4 = context.GetChild(3);
        CreateMenu(new string[] { "41", "42", "43", "44", "45" }, c4);
        var c45 = c4.GetChild(4);
        CreateMenu(new string[] { "451", "452", "453", "454", "455" }, c45);
        view.popMenu.Refresh();
    }
    void CreateMenu(string[] str,MenuContext parent)
    {
        for(int i=0;i<str.Length;i++)
        {
            MenuContext mc = new MenuContext();
            mc.Content = str[i];
            mc.SetParent(parent);
        }
    }
}
